package cn.melon.view.control;

import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;

/**
 * @ClassName: AccountInputTip
 * @author Hzy
 * 监听器，用于实现账户输入框提示文本的功能
 */
public class AccountInputTip implements FocusListener{
	private JTextField accountInput;
	private String tip;
	public AccountInputTip(JTextField accountInput,String tip){
		this.accountInput = accountInput;
		this.tip = tip;
	}
	
	@Override
	public void focusGained(FocusEvent e){
		if(accountInput.getText().equals(tip)){
//			获得焦点且其中文本为提示文本时，设置字体颜色，并清空tip
			accountInput.setForeground(Color.BLACK);
			accountInput.setText("");
		}
	}
	
	@Override
	public void focusLost(FocusEvent e){
		if(accountInput.getText().equals("")){
//			失去焦点且其中文本为空时，设置字体颜色，并设置tip
			accountInput.setForeground(Color.gray);
			accountInput.setText(tip);
		}
	}
}
